package com.tansun.easycare.rule.datamodel.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.tansun.easycare.rule.common.JsonMessage;
import com.tansun.easycare.rule.common.RuleBaseController;
import com.tansun.easycare.rule.common.model.ResponseVO;
import com.tansun.easycare.rule.datamodel.entity.RuleDatamodel;
import com.tansun.easycare.rule.datamodel.entity.RuleDataset;
import com.tansun.easycare.rule.datamodel.service.DataModelService;
import com.tansun.rule.utils.StringUtils;

/**
 * 数据模型Action
 *
 * @author Lph
 */
@Controller
@RequestMapping(value = "/ruleProj/dataModelRank")
public class DataModelRankController extends RuleBaseController {
    private static final Logger logger = LoggerFactory.getLogger(DataModelRankController.class);

    @Autowired
    private DataModelService dataModelService;

    /**
     * 进入数据模型管理页面
     */
    @RequestMapping("datasetDialog")
    public String index(HttpServletRequest request, HttpServletResponse response, String projectCode,String datasetId,RuleDatamodel ruleDatamodel,ModelMap map) throws Exception {

    	if (StringUtils.isEmpty(projectCode)) {
            projectCode = this.getCurrProjectCode();
        }
        ruleDatamodel.setProjectCode(projectCode);
        PageInfo<RuleDatamodel> page = this.dataModelService.findRuleDatamodelPage(new Page<RuleDatamodel>(),ruleDatamodel);
        map.put("name", ruleDatamodel.getName());
        map.put("chzn", ruleDatamodel.getChzn());
        map.put("page", page);
        map.put("projectCode", projectCode);
        map.put("datasetId", datasetId);
        return "rule/dataModelRank/datasetDialog";
    }
    @RequestMapping("updateDMRank")
    public @ResponseBody ResponseVO updateDMRank(String dmId,String datasetId) throws Exception {
    	JsonMessage ret = new JsonMessage();
    	try {
    		RuleDataset dataset = new RuleDataset();
    		dataset.setDatamodelid(dmId);
    		dataset.setId(datasetId);
    		dataModelService.updateDMRank(dataset);;
		} catch (Exception e) {
			// TODO: handle exception
		}
    	ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(200);
    	return responseVO;
    }
    
}
